package com.hxx.day5;

import org.junit.Test;

import java.util.*;

public class TestDemo2 {
    public static void main(String[] args) {
        Map map = new HashMap();
        map.put(1, "张三1");
        map.put(2, "张三2");
        map.put(3, "张三3");
        System.out.println("------按照key获取------");
        System.out.println(map.get(1));
        System.out.println("------获取所有的key------");
        Set keys = map.keySet();
        for (Object key : keys) {
            System.out.println(key + ":" + map.get(key));
        }
        System.out.println("-----获取所有的值-------");
        Collection values = map.values();
        values.stream().iterator().forEachRemaining(System.out::println);
        System.out.println("-----获取entry，获取key和value-------");
        Set entrySet = map.entrySet();
        for (Object entry : entrySet) {
            Map.Entry entry1 = (Map.Entry) entry;
            System.out.println(entry1.getKey() + ":" + entry1.getValue());
        }
    }

    /**
     * 数组帮助类Arrays
     */
    @Test
    public void test1() {
        int[] arr = {3,1,6,2,5};
        //排序
        Arrays.sort(arr);
        Arrays.stream(arr).forEach(System.out::println);
        System.out.println("---------");
        //两分法查找
        int index = Arrays.binarySearch(arr, 5);
        System.out.println(index);
    }

    /**
     * 集合 帮助类Collections
     */
    @Test
    public void test2() {
        List list = new ArrayList();
        list.add(3);
        list.add(1);
        list.add(6);
        list.add(2);
        list.add(5);

        //排序
        Collections.sort(list);
        list.stream().forEach(System.out::println);
    }
    @Test
    public void test3() {
        Set set = new HashSet();
        set.add(3);
        set.add(1);
        set.add(6);

        List list = new ArrayList(set);
        Collections.sort( list);
        list.stream().forEach(System.out::println);
        System.out.println("---------");
        Collections.reverse(list);
    }
}



















